(function (window) {
    function Switch(x, y, stroke, status, onWire) {
        //console.log(this.coordinates);
        this.initialize(x,y, stroke, status, onWire);
    }

    Switch.prototype = new Shape();

    Switch.prototype.Shape_initialize = Switch.prototype.initialize;

    /* Constructor */
    Switch.prototype.initialize = function (x,y, stroke, status, onWire) {
        this.Shape_initialize();
        this.coordinates = [x, y];
        this.stroke = stroke;
        this.status = status;
        this.onWire = onWire;
        this.activate(this.coordinates, this.stroke, this.status, this.onWire);
    }

    /* Public Methods */
    Switch.prototype.getShape = function (coordinates, stroke, status, onWire) {
        this.graphics.clear();
        if (status == "On") {
            this.closeSwitch(this);
        } else {
            this.openSwitch(this);
        }
    }

    Switch.prototype.closeSwitch = function (clickedSwitch) {
        var x = clickedSwitch.coordinates[0];
        var y = clickedSwitch.coordinates[1];

        clickedSwitch.graphics.clear();
        clickedSwitch.graphics.setStrokeStyle(clickedSwitch.stroke, "round", "round");
        clickedSwitch.graphics.beginStroke("#00B");
        clickedSwitch.graphics.drawCircle(x, y, 5);
        clickedSwitch.graphics.moveTo(x, y);
        clickedSwitch.graphics.lineTo(x + 50, y);
        clickedSwitch.graphics.moveTo(x + 50, y);
        clickedSwitch.graphics.drawCircle(x + 50, y, 5);
        clickedSwitch.graphics.beginStroke("#000");
        clickedSwitch.graphics.moveTo(x + 50, y);
        clickedSwitch.graphics.lineTo(x + 100, y);
        clickedSwitch.graphics.endStroke();

        /* while (tempY < y) { 
        console.log(tempY);
        tempY++;
        clickedSwitch.graphics.drawCircle(x, y, 5);
        clickedSwitch.graphics.moveTo(x, y);
        clickedSwitch.graphics.lineTo(x + 30, tempY);
        clickedSwitch.graphics.moveTo(x + 50, y);
        clickedSwitch.graphics.drawCircle(x + 50, y, 5);
        clickedSwitch.graphics.beginStroke("#000");
        clickedSwitch.graphics.moveTo(x + 50, y);
        clickedSwitch.graphics.lineTo(x + 100, y);
        alert("animation");

        clickedSwitch.parent.update();
        } */
    }

    Switch.prototype.openSwitch = function (clickedSwitch) {
        var x = clickedSwitch.coordinates[0];
        var y = clickedSwitch.coordinates[1];
        clickedSwitch.graphics.clear();
        clickedSwitch.graphics.setStrokeStyle(clickedSwitch.stroke, "round", "round");
        clickedSwitch.graphics.beginStroke("#00B");
        clickedSwitch.graphics.drawCircle(x, y, 5);
        clickedSwitch.graphics.moveTo(x, y - 40);
        clickedSwitch.graphics.lineTo(x + 50, y);
        clickedSwitch.graphics.moveTo(x + 50, y);
        clickedSwitch.graphics.drawCircle(x + 50, y, 5);
        clickedSwitch.graphics.beginStroke("#000");
        clickedSwitch.graphics.moveTo(x + 50, y);
        clickedSwitch.graphics.lineTo(x + 100, y);
        clickedSwitch.graphics.endStroke();
    }

    Switch.prototype.activate = function (coordinates, stroke, status, onWire) {
        this.getShape(coordinates, stroke, status, onWire);
    }

    Switch.prototype.tick = function () {

    }

    window.Switch = Switch;
} (window));